﻿



import Request from '../../base/request.js?t=202511041006'
import Storage from '../../base/storage.js?t=202511041006'
import { dealTime, downloadfun, queryURLParams, IgetDeptList, getBrowserInfo, previewCom, isImageFile, debounce} from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {




    const popContent = (text, name,maxlength=6) => {
        let hdiv = () => h('div', {
            style: `max-width: 600px;cursor:pointer`
        }, {
            default: () => text
        });
        const pop = () => h(antd.Popover, {
            title: name,
            content: hdiv(),
        }, () => [text.length > maxlength ? text.slice(0, maxlength) + '...' : text]);

        return h('div', {
        }, { default: () => [pop()] })
    }





    const data = reactive({
        messageTest: "",
        proxy: "",
        popTitle: "",
        cIndex: 1,
        previewInfo: {
            pdfurl: "",
            pdfOpen: false,
            previewShow: false,
            imgUrl: ""
        },
        isOut:false,
        uploadImg: {
            fileList: [

            ]
        },
        uinfo: {

        },
        IsValidList: [
            { label: "有效", value: true },
            { label: "停用", value: false },
        ],
        IsTrainingList: [
            { label: "是", value: true },
            { label: "否", value:false },
        ],
        formData1: {
            DepartmentId: null,//部门
            EmployeeNo: null,//工号
            EmployeeName: null,//姓名
            CertiType: null,//持证类别
            CertiNo: null,//证号
            ValidStartTime: null,//初次时间
            ValidEndTime: null,//期止时间
            CheckTime: null,//复审时间
            //OperateProject: null,
            JobTitle: null,//职位
            IsTraining: false,//是否培训
            //JobType: null,//
            //Talent: null,
            IsValid: true,//有效状态
            Sort: null,//有效状态
        },
        formRules1: {
            EmployeeNo: [
                { required: true, message: '请输入工号', trigger: 'change' }
            ],
            EmployeeName: [
                { required: true, message: '请输入姓名', trigger: 'change' }
            ],
            DepartmentId: [
                { required: true, message: '请选择部门', trigger: 'change' }
            ],
            CertiType: [
                { required: true, message: '请选择证书类别', trigger: 'change' }
            ],
            CertiNo: [
                { required: true, message: '请输入证书编号', trigger: 'change' }
            ],
            ValidEndTime: [
                { required: true, message: '请选择期止时间', trigger: 'change' }
            ],
        },
  
        formData2: {
            DepartmentId: null,//部门
            EmployeeNo: null,//工号
            EmployeeName: null,//姓名
            CertiType: null,//持证类别
            CertiNo: null,//证号
            ValidStartTime: null,//初次时间
            ValidEndTime: null,//期止时间
            CheckTime: null,//复审时间
            //OperateProject: null,
            JobTitle: null,//职位
            IsTraining: false,//是否培训
            JobType: null,//现从事专业
            Talent: null,//特长
            IsValid: true,//有效状态
        },
        formRules2: {
            EmployeeNo: [
                { required: true, message: '请输入工号', trigger: 'change' }
            ],
            DepartmentId: [
                { required: true, message: '请选择部门', trigger: 'change' }
            ],
            EmployeeName: [
                { required: true, message: '请输入姓名', trigger: 'change' }
            ],
            CertiType: [
                { required: true, message: '请选择证书类别', trigger: 'change' }
            ],
            CertiNo: [
                { required: true, message: '请输入证书编号', trigger: 'change' }
            ],
            ValidEndTime: [
                { required: true, message: '请选择期止时间', trigger: 'change' }
            ],
            //JobTitle: [
            //    { required: true, message: '请填写岗位名称', trigger: 'change' }
            //],
        },

        formData3: {
            DepartmentId: null,//部门
            EmployeeNo: null,//工号
            EmployeeName: null,//姓名
            CertiType: null,//持证类别
            CertiNo: null,//证号
            ValidStartTime: null,//初次时间
            ValidEndTime: null,//期止时间
            CheckTime: null,//复审时间
            OperateProject: null,//操作项目
            //JobTitle: null,//职位
            IsTraining: false,//是否培训
            //JobType: null,//
            //Talent: null,
            IsValid: true,//有效状态
        },
        formRules3: {
            EmployeeNo: [
                { required: true, message: '请输入工号', trigger: 'change' }
            ],
            EmployeeName: [
                { required: true, message: '请输入姓名', trigger: 'change' }
            ],
            DepartmentId: [
                { required: true, message: '请选择部门', trigger: 'change' }
            ],
            CertiType: [
                { required: true, message: '请选择证书类别', trigger: 'change' }
            ],
            CertiNo: [
                { required: true, message: '请输入证书编号', trigger: 'change' }
            ],
            ValidEndTime: [
                { required: true, message: '请选择期止时间', trigger: 'change' }
            ],
            JobTitle: [
                { required: true, message: '请填写岗位名称', trigger: 'change' }
            ],
            //CheckTime: [
            //    { required: true, message: '请选择复查时间', trigger: 'change' }
            //],
        },

        tabList: [
 
        ],
        queryParams: {
            IsValid: null,
            certiType: null,
            Status:true,
            IsTraining: null,
            EmployeeNo: null,
            DepartmentId: null,
            warningLevel: null
        },
        CertiTypeList:[],
        personTypeMap: {
            1: '企业负责人安全资质', 2: '安全专职人员资质', 3: '特种相关人员资质'
        },
        urlinfo: {},
        popType: null,
        uploadLock: false,
        opType: true,
        popShow: false,

        pagination: {
            total: 0,
            current: 1,
            pageSize: 20,
            loading: true,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 20,
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },
        levelList: [
            { label: '正常', value: 0, color: '#21b180', Count: 0 },
            { label: '90天内到期', value: 1, color: '#e5c51a', Count: 0 },
            { label: '30天内到期', value: 2, color: '#ff562b', Count: 0 },
            { label: '已过期', value: 3, color: '#d92223', Count: 0 },
        ],
        citem: {},
        deptList: [],
        columns1: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'left',
                width: 60,
                fixed: 'left',
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },

            {
                title: '数据状态',
                dataIndex: 'IsValid',
                key: 'IsValid',
                align: 'left',
                width: 80,
                customRender: function ({ text }) {
                    let textc = h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text == true ? '有效' : '停用' });
                    return textc
                }
            },
            {
                title: '剩余天数',
                dataIndex: 'Days',
                key: 'Days',
                align: 'left',
                width: 80,
                customRender: ({ text }) => {
                    // 默认值处理
                    if (!text && text !== 0) text = 0;
                    const num = Number(text);

                    // 颜色规则定义（按顺序匹配）
                    const colorRules = [
                        { condition: num > 90, color: '#21b180' },
                        { condition: num > 50, color: '#e5c51a' },
                        { condition: num >= 0, color: '#ff562b' },
                        { condition: true, color: '#d92223' } // 默认兜底（即 num < 0）
                    ];

                    // 找到第一个满足条件的颜色
                    const matchedRule = colorRules.find(rule => rule.condition) || {};
                    const color = matchedRule.color || '#999';

                    const tag = h(antd.Tag, {
                        style: { color: '#fff', backgroundColor: color, borderColor: color }
                    }, { default: () => `${num}天` });

                    return tag;
                }
            },

     
            {
                title: '姓名(工号)',
                dataIndex: 'FactoryAreaName',
                key: 'FactoryAreaName',
                align: 'left',
                width: 100,
                customRender: function ({  record }) {
                    return `${record.EmployeeName}(${record.EmployeeNo})`
                }
            },
            {
                title: '职务',
                dataIndex: 'JobTitle',
                key: 'JobTitle',
                align: 'left',
                width: 120,
                customRender: function ({ text }) {
                    return popContent(text,'职务')
                }
                     
            },
  
            {
                title: '证书有效期',
                dataIndex: 'ValidEndTime',
                key: 'ValidEndTime',
                align: 'left',
                width: 110,
                sortDirections: ['descend'],
                sorter: (a, b) => a.vt - b.vt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '已安排培训',
                dataIndex: 'IsTraining',
                key: 'IsTraining',
                align: 'left',
                width: 80,
                customRender: function ({ text }) {
                    let textc = h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text ? '是' : '否' });
                    return textc
                }
     
            },
            {
                title: '账号状态',
                dataIndex: 'Status',
                key: 'Status',
                align: 'left',
                width: 120,
                customRender: function ({ text }) {
                    return h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text == true ? '正常' : '停用' });
                }
            },
            {
                title: '更新时间',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'left',
                width: 130,
                sortDirections: ['descend'],
                sorter: (a, b) => a.ut - b.ut,
                customRender: function ({ text, record, index, column }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
      
            {
                title: '复审日期',
                dataIndex: 'CheckTime',
                key: 'CheckTime',
                align: 'left',
                width: 100,
                sortDirections: ['descend'],
                sorter: (a, b) => a.rt - b.rt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '持证类型',
                dataIndex: 'CertiTypeName',
                key: 'CertiTypeName',
                align: 'left',
                width: 120
            },
            {
                title: '所在部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'left',
                width: 120
            },
      
            {
                title: '操作',
                key: 'action',
                align: 'left',
                width: 120,
                fixed: 'right',
                customRender: function ({  record }) {

                    const FDBtn = h(antd.Popconfirm, {
                        title: `提示：安全负责人【${record.EmployeeName}(${record.EmployeeNo})】，删除后将无法恢复，请您确认。`,
                        onConfirm: () => methods.handleDelete(record)

                    }, { default: () => [delBtn] })

                    let detailBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleDetail(record)
                    }, { default: () => '详情' })

                    let editBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleEdit(record)
                    }, { default: () => '编辑' })

                    let delBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        danger:true

                    }, { default: () => '删除' })


                    return h(antd.Space, {
                    },
                        { default: () => [params.uinfo.value.DepartmentId == 20 ? editBtn : null, params.uinfo.value.DepartmentId == 20 ?FDBtn:null, detailBtn] }
                    );

                }
            },
        ],



        dataSource: [],
        columns2: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'left',
                width: 60,
                fixed: 'left',
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },

            {
                title: '数据状态',
                dataIndex: 'IsValid',
                key: 'IsValid',
                align: 'left',
                width: 80,
                customRender: function ({ text }) {
                    let textc = h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text == true ? '有效' : '停用' });
                    return textc
                }
            },
            {
                title: '剩余天数',
                dataIndex: 'Days',
                key: 'Days',
                align: 'left',
                width: 80,
                customRender: ({ text }) => {
                    // 默认值处理
                    if (!text && text !== 0) text = 0;
                    const num = Number(text);

                    // 颜色规则定义（按顺序匹配）
                    const colorRules = [
                        { condition: num > 90, color: '#21b180' },
                        { condition: num > 30, color: '#e5c51a' },
                        { condition: num >= 0, color: '#ff562b' },
                        { condition: true, color: '#d92223' } // 默认兜底（即 num < 0）
                    ];

                    // 找到第一个满足条件的颜色
                    const matchedRule = colorRules.find(rule => rule.condition) || {};
                    const color = matchedRule.color;

                    const tag = h(antd.Tag, {
                        style: { color: '#fff', backgroundColor: color, borderColor: color }
                    }, { default: () => `${num}天` });

                    return tag;
                }
            },

            {
                title: '所在部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'left',
                width: 110,
                customRender: function ({ record,text }) {
                    return popContent(text, '所在部门')
                }

          
            },
            {
                title: '姓名(工号)',
                dataIndex: 'FactoryAreaName',
                key: 'FactoryAreaName',
                align: 'left',
                width: 120,
                customRender: function ({ record }) {
                    return `${record.EmployeeName}(${record.EmployeeNo})`
                }
            },
            {
                title: '证号',
                dataIndex: 'CertiNo',
                key: 'CertiNo',
                align: 'left',
                width: 140,
            },
            {
                title: '持证类型',
                dataIndex: 'CertiTypeName',
                key: 'CertiTypeName',
                align: 'left',
                width: 120,
                customRender: function ({ record, text }) {
                    return popContent(text, '持证类型')
                }
            },
   
            {
                title: '证书有效期',
                dataIndex: 'ValidEndTime',
                key: 'ValidEndTime',
                align: 'left',
                width: 110,
                sortDirections: ['descend'],
                sorter: (a, b) => a.vt - b.vt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },

            {
                title: '账号状态',
                dataIndex: 'Status',
                key: 'Status',
                align: 'left',
                width: 120,
                customRender: function ({ text }) {
                    return h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text == true ? '正常' : '停用' });
                }
            },
            {
                title: '更新时间',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'left',
                width: 90,
                sortDirections: ['descend'],
                sorter: (a, b) => a.ut - b.ut,
                customRender: function ({ text, record, index, column }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '复审日期',
                dataIndex: 'CheckTime',
                key: 'CheckTime',
                align: 'left',
                width: 120,
                sortDirections: ['descend'],
                sorter: (a, b) => a.rt - b.rt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '操作',
                key: 'action',
                align: 'left',
                width: 120,
                fixed: 'right',
                customRender: function ({ record }) {

                    const FDBtn = h(antd.Popconfirm, {
                        title: `提示：安全专职人员【${record.EmployeeName}(${record.EmployeeNo})】，删除后将无法恢复，请您确认。`,
                        onConfirm: () => methods.handleDelete(record)

                    }, { default: () => [delBtn] })

                    let detailBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleDetail(record)
                    }, { default: () => '详情' })

                    let editBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleEdit(record)
                    }, { default: () => '编辑' })

                    let delBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        danger: true

                    }, { default: () => '删除' })


                    return h(antd.Space, {
                    },
                        { default: () => [params.uinfo.value.DepartmentId == 20 ? editBtn : null, params.uinfo.value.DepartmentId == 20 ? FDBtn : null, detailBtn] }
                    );

                }
            },
        ],
        columns3: [
            {
                title: '序号',
                dataIndex: 'index',
                key: 'index',
                align: 'left',
                width: 60,
                fixed: 'left',
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },

            {
                title: '数据状态',
                dataIndex: 'IsValid',
                key: 'IsValid',
                align: 'left',
                width: 80,
                customRender: function ({ text }) {
                    let textc = h(antd.Tag, {
                        color: text == true ? "#4acb63" :"#9e9e9e",
                    }, { default: () => text == true ? '有效':'停用' });
                    return textc
                }
            },
            {
                title: '剩余天数',
                dataIndex: 'Days',
                key: 'Days',
                align: 'left',
                width: 80,
                customRender: ({ text }) => {
                    // 默认值处理
                    if (!text && text !== 0) text = 0;
                    const num = Number(text);

                    // 颜色规则定义（按顺序匹配）
                    const colorRules = [
                        { condition: num > 90, color: '#21b180' },
                        { condition: num > 30, color: '#e5c51a' },
                        { condition: num >= 0, color: '#ff562b' },
                        { condition: true, color: '#d92223' } // 默认兜底（即 num < 0）
                    ];

                    // 找到第一个满足条件的颜色
                    const matchedRule = colorRules.find(rule => rule.condition) || {};
                    const color = matchedRule.color || '#999';

                    const tag = h(antd.Tag, {
                        style: { color: '#fff', backgroundColor: color, borderColor: color }
                    }, { default: () => `${num}天` });

                    return tag;
                }
            },


            {
                title: '姓名(工号)',
                dataIndex: 'FactoryAreaName',
                key: 'FactoryAreaName',
                align: 'left',
                width: 120,
                customRender: function ({ record }) {
                    return `${record.EmployeeName}(${record.EmployeeNo})`
                }
            },
            {
                title: '证号',
                dataIndex: 'CertiNo',
                key: 'CertiNo',
                align: 'left',
                width: 120,
            },
            {
                title: '持证类型',
                dataIndex: 'CertiTypeName',
                key: 'CertiTypeName',
                align: 'left',
                width: 100,
                customRender: function ({ record, text }) {
                    return popContent(text, '持证类型')
                }
            },

      
      
            //{
            //    title: '有效期起',
            //    dataIndex: 'ValidStartTime',
            //    key: 'ValidStartTime',
            //    align: 'left',
            //    customRender: function ({ text }) {
            //        return dealTime(text, 'YYYY-MM-DD HH:mm')
            //    }
            //},
            {
                title: '所在部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'left',
                width: 100,
                customRender: function ({ record, text }) {
                    return popContent(text, '所在部门',5)
                }
            },
            {
                title: '有效期',
                dataIndex: 'ValidEndTime',
                key: 'ValidEndTime',
                align: 'left',
                width: 90,
                sortDirections: ['descend'],
                sorter: (a, b) => a.vt - b.vt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '复审日期',
                dataIndex: 'CheckTime',
                key: 'CheckTime',
                align: 'left',
                width: 90,
                sortDirections: ['descend'],
                sorter: (a, b) => a.rt - b.rt,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
            {
                title: '账号状态',
                dataIndex: 'Status',
                key: 'Status',
                align: 'left',
                width: 120,
                customRender: function ({ text }) {
                    return h(antd.Tag, {
                        color: text == true ? "#4acb63" : "#9e9e9e",
                    }, { default: () => text == true ? '正常' : '停用' });
                }
            },
            {
                title: '更新时间',
                dataIndex: 'UpdateTime',
                key: 'UpdateTime',
                align: 'left',
                width: 120,
                sortDirections: ['descend'],
                sorter: (a, b) => a.ut - b.ut,
                customRender: function ({ text }) {
                    return text ? dealTime(text, 'YYYY-MM-DD') : '-'
                }
            },
 
            {
                title: '操作',
                key: 'action',
                align: 'left',
                width: 120,
                fixed: 'right',
                customRender: function ({ record }) {

                    const FDBtn = h(antd.Popconfirm, {
                        title: `提示：特种作业相关人员【${record.EmployeeName}(${record.EmployeeNo})】，删除后将无法恢复，请您确认。?`,
                        onConfirm: () => methods.handleDelete(record)

                    }, { default: () => [delBtn] })

                    let detailBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleDetail(record)
                    }, { default: () => '详情' })

                    let editBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        onClick: () => methods.handleEdit(record)
                    }, { default: () => '编辑' })

                    let delBtn = h(antd.Button, {
                        type: "link",
                        size: 'small',
                        danger: true

                    }, { default: () => '删除' })


                    return h(antd.Space, {
                    },
                        { default: () => [params.uinfo.value.DepartmentId == 20 ? editBtn : null, params.uinfo.value.DepartmentId == 20 ? FDBtn : null, detailBtn] }
                    );

                }
            },
        ],
        dataSource3: [],
        cIds:[]

    })
    let params = toRefs(data)
    const methods = {
        tchange: () => {
            Storage.set(`${window.location.pathname}Index`, params.cIndex.value, true)
            params.queryParams.value = {
                IsValid: null,
                IsTraining: null,
                Status:true,
      
            }
            methods.getTableList(true)
            methods.IGetStatusCount()
            methods.IGetCertiTypeList()
        },

        handleSearch: (status) => {
            params.queryParams.value.warningLevel = status
            methods.getTableList(true)
        },

        getinfoByno: () => {
         
            
        },
        handleInput: debounce(() => {
            params.uploadLock.value = true
            Request({
                url: `/SafetyCertification/GetEmployeeInfo`,
                method: 'post',
                params: {
                    EmployeeNo: params[`formData${params.cIndex.value}`].value.EmployeeNo
                }
            }).then(res => {
                if (res.Code == 100) {
            
       
                    if (res.Data.name && res.Data.Valid == false) {
                        params.isOut.value = true
                    } else {
                        params.isOut.value = false
                    }
                    params[`formData${params.cIndex.value}`].value.DepartmentId = +res.Data.directlyDepartId
                    params[`formData${params.cIndex.value}`].value.EmployeeName = res.Data.name
                

                }
            }).finally(() => {
                params.uploadLock.value = false
            })
            
        }, 1000),

        handleImport: (info,type) => {
            if (!params.uploadLock.value) {
                params.uploadLock.value = true
                let formData = new FormData();
                formData.append('file', info.file.originFileObj)
                formData.append('Type', params.cIndex.value)
                if (type == 0) {
                    Request({
                        url: `/SafetyCertification/ImportOldData`,
                        method: 'post',
                        data: formData
                    }).then(res => {
                        params.messageTest.value.success('导入成功');
                        methods.getTableList(true)
                        params.uploadLock.value = false
                    })
                } else {
                    Request({
                        url: `/SafetyCertification/ImportData`,
                        method: 'post',
                        data: formData
                    }).then(res => {
                        params.messageTest.value.success('导入成功');
                        methods.getTableList(true)
                        params.uploadLock.value = false
                    })
                }
       

            }
        },

        handleExport: () => {
            params.uploadLock.value = true
            Request({
                url: `/SafetyCertification/ExportData`,
                method: 'post',
                data: {
                    model: {
                        ...params.queryParams.value,
                        TypeId: params.cIndex.value
                    },
                    IdList: params.cIds.value
             
                }
            }).then(res => {
                if (!res.Data) {
                   return params.messageTest.value.info("获取下载地址失败")
                }
                let ss = res.Data
                const match = ss.split('/')[ss.split('/').length - 1].split('.')[0]
                if (match) {
                
                    downloadfun(match, res.Data)
                } else {
                    console.log('未匹配到文件名称')
                }


             
            }).finally(() => {
                params.uploadLock.value = false
            })
        },
        IGetCertiTypeList: () => {
            params.uploadLock.value = true
            Request({
                url: `/SafetyCertification/GetCertiTypeList`,
                method: 'post',
                data: {
                    TypeId: params.cIndex.value
                }
            }).then(res => {
                params.CertiTypeList.value = res.Data?.map(e => ({ label: e.TypeValue, value: e.Id }))
            }).finally(() => {
                params.uploadLock.value = false
            })
        },
        handleReset: () => {
            params.queryParams.value = {
                IsValid: null,
                IsTraining: null
            }
            methods.getTableList(true)
        },
        IGetTypeList: () => {
            params.uploadLock.value = true
            Request({
                url: `/SafetyCertification/GetTypeList`,
                method: 'post',
            }).then(res => {
                params.tabList.value = res.Data?.map(e => ({ label: e.TypeValue, value: e.Id }))
            }).finally(() => {
                params.uploadLock.value = false
            })
        },

        handleChange: (info) => {
            let subarrys = info.fileList.filter(e => !e.old).map(e => e.originFileObj)

            if (!params.uploadLock.value) {
                params.uploadLock.value = true
                let formData = new FormData();
   
                for (let e of subarrys) {
                    formData.append('file', e)
                }
                Request({
                    url: `/download/uploadfile?Path=SafetyCertification`,
                    method: 'post',
                    data: formData
                }).then(res => {
                    params.uploadImg.value.fileList = [
                        ...res.Data.map(e => {
                            const { FilePath, FileName } = e
                            e.url = FilePath
                            e.name = FileName
                            return e
                        }),
                        ...params.uploadImg.value.fileList.filter(e => e.FileId)
                    ]
     
                }).finally(() => {
                    params.uploadLock.value = false
                })

            }
        },

         rowSelection : {
             onChange: (selectedRowKeys, selectedRows) => {
                 params.cIds.value = selectedRowKeys
            },
            getCheckboxProps: (record) => ({
            }),
        },
        getDeptList: () => {
            return new Promise(async (resolve, rej) => {
                params.deptList.value = await IgetDeptList(Request)
                if (params.deptList.value) {
                    resolve(1)
                }
            })


        },

        itemRender: (data, type) => {
            let uid = data.file.FileId
     
              var btnPreview=(e) => {
                  let item = params.uploadImg.value.fileList.find(es => es.FileId == e)
                  item.url = item.FilePath || item.url
                if (item.FileName.indexOf('.pdf') != -1) {
                    params.previewInfo.value.pdfUrl = item.url
                    params.previewInfo.value.pdfOpen = true
                } else {
                    params.previewInfo.value.imgUrl = item.url
                    params.previewInfo.value.previewShow = true
                }
            }
            var btnDownLoad= (e) => {
                let item = params.uploadImg.value.fileList.find(es => es.FileId == e)
                    item.url = item.FilePath || item.url
                    const { name, url } = item
                    params.uploadLock.value = true
                    downloadfun(name, url).finally(() => {
                        params.uploadLock.value = false
                    })
             }
            var btnDelete=(e) => {
                        const { FileId } = e.file
                        if (FileId) {
                            params.uploadLock.value = true
                            methods.IDeleteFile(FileId).then(res => {
                                params.uploadImg.value.fileList = params.uploadImg.value.fileList.filter(e => e.FileId != FileId)
                                params.messageTest.value.success(res.Msg);
                            }).catch(err => {
                                console.log(err, 'err')
                            }).finally(() => {
                                params.uploadLock.value = false
                            })
                        }
                    }
            const previewBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { btnPreview(uid, type) }, src: "../Bussiness/img/svg/preview.svg", width: 20, height: 22 }, { default: () => '预览' })
            const downloadBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { btnDownLoad(uid, type) }, src: "../Bussiness/img/svg/download.svg", width: 20, height: 22 }, { default: () => '下载' })
            const deleteBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', src: "../Bussiness/img/svg/delete.svg", width: 18, height: 22 }, { default: () => '删除' })
            const FDBtn = h(antd.Popconfirm, {
                title: "确定删除此文件？确定后不可恢复",
                onConfirm: () => btnDelete(data, type)

            }, { default: () => [deleteBtn] })
            var btns = h('div', { style: "display:flex;margin-left:10px" }, {
                default: () => [
                    isImageFile(data.file.url) ? previewBtn : null,
                    downloadBtn,
               params.popType.value == 9 ? null : FDBtn
                ]
            })
            return h('div', { style: 'margin-top:10px; width:400px;align-items:center; display:flex;justify-content:space-between' }, {
                default: () => [
                    data.file.name, btns
                ]
            })

        },


        reset: () => {



            params.formData1.value = {
                DepartmentId: null,//部门
                EmployeeNo: null,//工号
                EmployeeName: null,//姓名
                CertiType: null,//持证类别
                CertiNo: null,//证号
                ValidStartTime: null,//初次时间
                ValidEndTime: null,//期止时间
                CheckTime: null,//复审时间
                //OperateProject: null,
                JobTitle: null,//职位
                IsTraining: false,//是否培训
                //JobType: null,//
                //Talent: null,
                IsValid: true,//有效状态
            }
            params.formData2.value = {
                DepartmentId: null,//部门
                EmployeeNo: null,//工号
                EmployeeName: null,//姓名
                CertiType: null,//持证类别
                CertiNo: null,//证号
                ValidStartTime: null,//初次时间
                ValidEndTime: null,//期止时间
                CheckTime: null,//复审时间
                //OperateProject: null,
                JobTitle: null,//职位
                IsTraining: false,//是否培训
                JobType: null,//现从事专业
                Talent: null,//特长
                IsValid: true,//有效状态
            }
            params.formData3.value = {
                DepartmentId: null,//部门
                EmployeeNo: null,//工号
                EmployeeName: null,//姓名
                CertiType: null,//持证类别
                CertiNo: null,//证号
                ValidStartTime: null,//初次时间
                ValidEndTime: null,//期止时间
                CheckTime: null,//复审时间
                OperateProject: null,//操作项目
                //JobTitle: null,//职位
                IsTraining: false,//是否培训
                //JobType: null,//
                //Talent: null,
                IsValid: true,//有效状态
            }

        },
        IDeleteFile: (id) => {
 
            return new Promise((resolve,rej) => {
                Request({
                    url: "/SafetyCertification/DeleteFile",
                    method: 'post',
                    data: {
                        Id: id
                    }
                }).then(res => {

                    resolve(res)
                }).catch(() => {
                    rej()
                })
            })
     
        },
        toAdd: () => {
            params.popType.value = null
            methods.reset()
            params.uploadImg.value.fileList =[]
            params.popShow.value = true
        },

        handleDetail : (item) => {
            params.popType.value = 9
            Request({
                url: "/SafetyCertification/GetSafetyCertificationInfo",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params[`formData${params.cIndex.value}`].value = {
                    ...res.Data, ValidEndTime: dayjs(dealTime(res.Data.ValidEndTime, 'YYYY-MM-DD'), 'YYYY-MM-DD'),
                    ValidStartTime: dayjs(dealTime(res.Data.ValidEndTime, 'YYYY-MM-DD'), 'YYYY-MM-DD'),
                    CheckTime: res.Data.CheckTime &&dayjs(dealTime(res.Data.CheckTime, 'YYYY-MM-DD'), 'YYYY-MM-DD')
                }
                params.uploadImg.value.fileList = res.Data.FileList.map(e => {
                    e.url = e.FilePath
                    e.name = e.FileName
                    e.old = true
                    return e
                })
                params.popShow.value = true
            })
        },

             handleEdit : (item) => {
            params.popType.value = 1
            Request({
                url: "/SafetyCertification/GetSafetyCertificationInfo",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params[`formData${params.cIndex.value}`].value = {
                    ...res.Data, ValidEndTime: dayjs(dealTime(res.Data.ValidEndTime, 'YYYY-MM-DD'), 'YYYY-MM-DD'),
                    ValidStartTime: dayjs(dealTime(res.Data.ValidEndTime, 'YYYY-MM-DD'), 'YYYY-MM-DD'),
                    CheckTime: res.Data.CheckTime&&dayjs(dealTime(res.Data.CheckTime, 'YYYY-MM-DD'), 'YYYY-MM-DD')
                }
                params.uploadImg.value.fileList = res.Data.FileList.map(e => {
                    e.url = e.FilePath
                    e.name = e.FileName
                    e.old = true
                    return e
                })
                params.popShow.value = true
            })
        },

                 handleDelete : (item) => {
            Request({
                url: "/SafetyCertification/DeleteSafetyCertificationInfo",
                method: 'post',
                data: {
                    Id: item.Id
                }
            }).then(res => {
                params.messageTest.value.success(res.Msg);
                methods.getTableList(true)
            })

        },
        handleOk: () => {
            if (params.popType.value == 9) {
                return params.popShow.value = false
            }
            params.proxy.value.$refs.formRef
                .validate()
                .then(() => {

                    if (params.popType.value == 1) {
                        Request({
                            url: "/SafetyCertification/EditSafetyCertification",
                            method: 'post',
                            data: { TypeId: params.cIndex.value, ...params[`formData${params.cIndex.value}`].value, FileList: params.uploadImg.value.fileList.filter(e => !e.old).map(e => e.FileId) }
                        }).then(res => {
                            params.messageTest.value.success(res.Msg);
                            methods.getTableList(true)
                            params.popShow.value = false
                        }).finally(() => {
                    
                        })
                    } else {
                        Request({
                            url: "/SafetyCertification/AddSafetyCertification",
                            method: 'post',
                            data: { TypeId: params.cIndex.value, ...params[`formData${params.cIndex.value}`].value, FileList: params.uploadImg.value.fileList.filter(e => !e.old).map(e => e.FileId) }
                        }).then(res => {
                            params.messageTest.value.success(res.Msg);
                            methods.getTableList(true)
                            params.popShow.value = false
                        }).finally(() => {
          
                        })
                    }
                })
                .catch(error => {
                    console.log('error', error);
                });
        },
     



        handleTableChange: (page, filters, sorter, { action }) => {
 
            if (action =='sort') {
                     
            } else {
                const { current, pageSize } = page
                params.pagination.value.current = current;
                params.pagination.value.pageSize = pageSize;
                methods.getTableList()
            }

 
        },

        getTableList: async (isRresh) => {
            if (isRresh) {
                params.pagination.value.current = 1
            }
            params.pagination.value.loading = true

            Request({
                url: "/SafetyCertification/GetSafetyCertificationPageList",
                method: 'post',
                params: {
                    page: params.pagination.value.current,
                    pageSize: params.pagination.value.pageSize
                },
                data: {
                    ...params.queryParams.value,
                    TypeId: params.cIndex.value
                }
            }).then(res => {
                params.dataSource.value = res.Data?.Data.map(e => {
                    e.vt = e.ValidEndTime && dayjs(dealTime(e.ValidEndTime)).valueOf()
                    e.ut = e.UpdateTime && dayjs(dealTime(e.UpdateTime)).valueOf()
                    e.rt = e.CheckTime && dayjs(dealTime(e.CheckTime)).valueOf()
                    return e
                })
                console.log(params.dataSource.value,' params.dataSource.value')
                params.pagination.value.total = res.Data?.TotalItemCount
            }).finally(() => {
                params.pagination.value.loading = false
            })

        },
        filterOption: (val, type) => {
            return `${type.label}`.includes(`${val || ''}`)
        },
        IGetStatusCount: () => {
            params.pagination.value.loading = true
            Request({
                url: "/SafetyCertification/GetStatusCount",
                method: 'post',
                data: {
                    TypeId: params.cIndex.value
                }
            }).then(res => {
                params.levelList.value[0].Count = res.Data[0].Count.length
                params.levelList.value[1].Count = res.Data[1].Count.length
                params.levelList.value[2].Count = res.Data[2].Count.length
                params.levelList.value[3].Count = res.Data[3].Count.length
            }).finally(() => {
                params.pagination.value.loading = false
            })
        },

        init: () => {
            getBrowserInfo().catch(err => { console.log(err) })
            if (proxy) {
                params.proxy.value = proxy
            }

            const key = `${window.location.pathname}Index`;
            const storedValue = Storage.get(key, true); // 获取原始值（字符串或 null）

            if (storedValue !== null && storedValue !== undefined && !isNaN(storedValue)) {
                params.cIndex.value = +Storage.get(`${window.location.pathname}Index`, true)
            }

            params.urlinfo.value = queryURLParams()
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });
            setTimeout(() => {
                let info = Storage.get('AccountInfo', true)
                params.uinfo.value = info
                Request({
                    url: "/Account/createJwtToken",
                    method: 'post',
                    data: {
                        "userName": info && info.UserNo
                    }
                }).then(async res => {
                    Storage.set('token', res.Data, true)
                    methods.IGetTypeList()
                    methods.IGetCertiTypeList()
                    methods.getDeptList()
                    methods.getTableList(true)
                    methods.IGetStatusCount()
                })
            }, 400)

        },
    }

    const template = {
        imageModel: previewCom(params, methods).imageModel,
        pdfPopModel: previewCom(params, methods).pdfPopModel,
    }
    return {
        ...params,
        ...methods,
        template
    }
}

export default Composition